var expross = require("../");
var app = expross();
var router = expross.Router();
var fs = require("fs");

app.engine("ntl", function(filePath, options, callback) {
  fs.readFile(filePath, function(err, content) {
    if (err) return callback(new Error(err));
    var rendered = content
      .toString()
      .replace("#title#", "<title>" + options.title + "</title>")
      .replace("#message#", "<h1>" + options.message + "</h1>");
    return callback(null, rendered);
  });
});
app.set("views", "./test/views"); // 制定视图所在的位置
app.set("view engine", "ntl"); //  注册模板引擎

app.get("/", function(req, res, next) {
  res.render("index", { title: "Hey", message: "Hello there!" });
});

// app.get("/", function(req, res, next) {
//   res.send("home");
// });

app.get("/books", function(req, res, next) {
  console.log(req.res);
  res.send("books");
});

router.use("/1", function(req, res, next) {
  res.send("first user");
});

router.use("/2", function(req, res, next) {
  res.send("second user");
});

app.use("/users", function() {
  console.log("router use");
});

app.listen(3000, function() {
  console.log("Example app listening on port 3000!");
});

// 源代码学习来自   https://github.com/WangZhechao/expross.git
